#include<bits/stdc++.h>
#define int long long
#define N 310
#define mod 1000000007
using namespace std;

int n, m, ans;
char a[N][N];
int op[N][N];
int Pow(int a, int n) {
	if(n == 0) return 1;
	if(n == 1) return a;
	int x = Pow(a, n / 2);
	if(n % 2 == 0) return x * x % mod;
	else return x * x % mod * a % mod;
}
int Sol1() {
	int D = 1;
	ans = 1;
	for(int i = 2; i <= m + 1; i++) {
		if(i == m + 1 || a[1][i] != a[1][i - 1]) {
			ans = ans * Pow(2, D - 1) % mod;
			D = 1;
		}
		else D++;
	}
	return ans;
}

void dfs(int x, int y) {
	if(x == n + 1) {
		ans++;
		return;
	}
	int nx = x, ny = y;
	if(y == m) nx++, ny = 1;
	else ny++;
	bool p1 = 0, p2 = 0;
	if(a[x - 1][y] == a[x][y] && op[x - 1][y] == 2) p1 = 1;
	if(a[x][y - 1] == a[x][y] && op[x][y - 1] == 1) p2 = 1;
	if(p1 && p2) return;
	else if(p1) {
		if(x < n && a[x][y] == a[x + 1][y]) {
			op[x][y] = 2;
			dfs(nx, ny);	
		}
		op[x][y] = 0;
		dfs(nx, ny);
	}
	else if(p2) {
		if(y < m && a[x][y] == a[x][y + 1]) {
			op[x][y] = 1;
			dfs(nx, ny);	
		}
		op[x][y] = 0;
		dfs(nx, ny);
	}
	else {
		if(x < n && a[x][y] == a[x + 1][y]) {
			op[x][y] = 2;
			dfs(nx, ny);	
		}
		if(y < m && a[x][y] == a[x][y + 1]) {
			op[x][y] = 1;
			dfs(nx, ny);	
		}
		op[x][y] = 0;
		dfs(nx, ny);
	}
}


int Sol2() {
	ans = 0;
	for(int i = 1; i <= n; i++)
	for(int j = 1; j <= m; j++) op[i][j] = 0;
	dfs(1, 1); 
	return ans;
} 

signed main() {
	freopen("disanti.in", "r", stdin);
	freopen("disanti.out", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	
	cin >> n >> m;
	for(int i = 1; i <= n; i++)
	for(int j = 1; j <= m; j++) cin >> a[i][j];
	
	if(n == 1) {
		for(int j = 1; j <= m; j++) {
			if(a[1][j] == '0') a[1][j] = '1';
			else a[1][j] = '0';
			cout << Sol1() << " "; 
			if(a[1][j] == '0') a[1][j] = '1';
			else a[1][j] = '0';
		}
		return 0;
	}
	
	
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			if(a[i][j] == '0') a[i][j] = '1';
			else a[i][j] = '0';
			cout << Sol2() << " "; 
			if(a[i][j] == '0') a[i][j] = '1';
			else a[i][j] = '0';
		}
		cout << endl;
	}
	
	return 0;
}
/*
2 2
01
00
*/


